/*
** Xin YUAN, 2024, BSD (2)
*/

////////////////////////////////////////////////////////////////////////////////

#include "diff_test.h"

////////////////////////////////////////////////////////////////////////////////

const char g_src1[] = "fdghtu gHtiyuj lltkdrr";
const uintptr_t g_src1_len = sizeof(g_src1) - 1;
const char g_src2[] = " dgh---xHT ghj yujxx pkrr";
const uintptr_t g_src2_len = sizeof(g_src2) - 1;

int test_diff() noexcept
{
	outputf_s(_s("==========test_diff===========\n"));

	CTL::PlainArray<CTL::LcsItem>  arrLCS;
	CTL::PlainArray<CTL::DiffItem> arrDiff;

	try {
		//case 1
		CTL::MyersDiff<char>(NULL, 0, NULL, 0, arrLCS);
		if ( arrLCS.GetSize() != 0 )
			CTL::ExceptionTraits::ThrowUnexpected();
		//case 2
		CTL::MyersDiff<char>(NULL, 0, g_src2, g_src2_len, arrLCS);
		if ( arrLCS.GetSize() != 0 )
			CTL::ExceptionTraits::ThrowUnexpected();
		//case 3
		CTL::MyersDiff<char>(g_src1, g_src1_len, NULL, 0, arrLCS);
		if ( arrLCS.GetSize() != 0 )
			CTL::ExceptionTraits::ThrowUnexpected();
		//case 4
		CTL::MyersDiff(g_src1, g_src1_len, g_src2, g_src2_len, arrLCS);
		if ( arrLCS.GetSize() == 0 )
			CTL::ExceptionTraits::ThrowUnexpected();
		CTL::LcsToDiff(arrLCS, g_src1_len, g_src2_len, arrDiff);
		if ( arrDiff.GetSize() == 0 )
			CTL::ExceptionTraits::ThrowUnexpected();
		for ( uintptr_t i = 0; i < arrDiff.GetSize(); i ++ ) {
			outputf_s(_s("%d %d %d %d %d\n"), arrDiff[i].iType,
					arrDiff[i].iStart1, arrDiff[i].iEnd1,
					arrDiff[i].iStart2, arrDiff[i].iEnd2);
		}
	}
	catch(...) {
		outputf_s(_s("test_diff: error\n"));
		outputf_s(_s("**********test_diff***********\n"));
		return 1;
	}

	outputf_s(_s("**********test_diff***********\n"));

	return 0;
}

////////////////////////////////////////////////////////////////////////////////
